package com.gjzt.business.bid.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eastdigit.servlet.ReqBean;
import com.eastdigit.servlet.RequestAttribute;
import com.eastdigit.servlet.Response;
import com.unionpay.acp.service.BackRcvResponse;
import com.unionpay.acp.service.DownloadFileTransferService;
import com.unionpay.acp.service.FrontRcvResponse;
import com.unionpay.acp.service.VerifyOrderService;
import com.unionpay.acp.service.consume.FrontConsume;

import net.sf.json.JSONObject;


/**
 * 保证金订单支付接口
 * 包含：前台支付、前台通知返回、后台通知返回、订单查询、对账文件获取
 * 
 * @author zwm
 *
 */

@Controller
@RequestMapping(value = "/payOrder")
public class PayOrderController {

    @Autowired
    private FrontConsume frontConsume;// 前台消费
    @Autowired
    private FrontRcvResponse frontRcvResponse;// 前台通知
    @Autowired
    private BackRcvResponse backRcvResponse;// 后台通知
    @Autowired
    private VerifyOrderService verifyOrderService;// 订单校验
    @Autowired
    private DownloadFileTransferService downloadFileTransferService;// 获取后台对账文件
    
    
    /**
     * 客户支付保证金
     * @param reqBean
     * @return
     * @throws IOException 
     * @throws ServletException 
     */
	@RequestMapping(value = "/payDeposit")
	@ResponseBody
	public void payDeposit(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException {
		// biddingForExternalService.payDeposit(reqBean);
		frontConsume.payDeposit(reqBean,req, resp);
	}
	
    /**
     * 前台通知
     * @param reqBean
     * @return
     * @throws IOException 
     * @throws ServletException 
     */
	@RequestMapping(value = "/frontNotice")
	@ResponseBody
	public void frontNotice(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException {
		// biddingForExternalService.payDeposit(reqBean);
		frontRcvResponse.frontNotice(req, resp);
	}
	
	 
    /**
     * 后台通知
     * @param reqBean
     * @return
     * @throws IOException 
     * @throws ServletException 
     */
	@RequestMapping(value = "/backNotice")
	@ResponseBody
	public void backNotice(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException {
		// biddingForExternalService.payDeposit(reqBean);
		backRcvResponse.backNotice(req, resp);
	}
	
  /**
     * 订单查询、校验
     * @param reqBean
     * @return
     * @throws IOException 
     * @throws ServletException 
     */
	@RequestMapping(value = "/queryOrder")
	@ResponseBody
	public JSONObject orderQuery(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException {
		 return Response.response(verifyOrderService.verifyOrder(req, resp));
	}
	
	/**
	 * 对账文件获取
	 * @param reqBean
	 * @param req
	 * @param resp
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping(value = "/downloadFileTransfer")
	@ResponseBody
	public JSONObject downloadFileTransfer(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest req,
			HttpServletResponse resp) throws ServletException, IOException {
		downloadFileTransferService.downloadFileTransfer(req, resp);
		resp.reset();
		return Response.responseSuccess();
		
	}
}